﻿using System;
using DBProvider.Providers;

namespace HealthCommunity.Controls
{
	public partial class UCCourseLog : System.Web.UI.UserControl
	{
		private ICourseProvider _CourseProvider;

		protected void Page_Load(object sender, EventArgs e)
		{
			if (!IsPostBack)
			{
				BindData();
			}
		}

		protected void btnSearch_Click(object sender, EventArgs e)
		{
			BindData();
		}

		private void BindData()
		{
			var user = SiteContext.Current.CurrentUser;

			if (user != null)
			{
				var start = new DateTime(1753, 1, 1, 0, 0, 0);
				var end = new DateTime(9999, 12, 31, 23, 59, 59);

				if (!string.IsNullOrEmpty(txtStartDate.Text.Trim()))
				{
					DateTime.TryParse(txtStartDate.Text.Trim(), out start);
				}

				if (!string.IsNullOrEmpty(txtEndDate.Text.Trim()))
				{
					DateTime.TryParse(txtEndDate.Text.Trim(), out end);
				}

				if (_CourseProvider == null)
				{
					_CourseProvider = new CourseProvider();
				}

				gvCourseLog.DataSource = _CourseProvider.GetRLT_UserAndCourseByUser(user.UserID, start, end);
				gvCourseLog.DataBind();
			}
		}
	}
}